package com.ckerchina.admin.ckadmin.controller.console;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ckerchina.admin.ckadmin.consts.ActorType;
import com.ckerchina.admin.ckadmin.controller.dto.MgrResponseData;
import com.ckerchina.admin.ckadmin.dao.AgentUserDao;
import com.ckerchina.admin.ckadmin.dao.MaterialDao;
import com.ckerchina.admin.ckadmin.dao.MaterialOrderDao;
import com.ckerchina.admin.ckadmin.dao.TeacherInfoDao;
import com.ckerchina.admin.ckadmin.domain.AgentUser;
import com.ckerchina.admin.ckadmin.domain.Material;
import com.ckerchina.admin.ckadmin.domain.MaterialOrder;
import com.ckerchina.admin.ckadmin.domain.TeacherInfo;
import com.ckerchina.admin.ckadmin.domain.mgr.MgrUser;
import com.ckerchina.admin.ckadmin.service.UpdateService;
import com.ckerchina.admin.ckadmin.utils.Page;


@Controller
public class AgentMaterialController extends AbstractConsoleController{

	@Autowired
	private MaterialOrderDao materialOrderDao;
	
	@RequestMapping("agentMaterial/list")	
	public @ResponseBody Page<MaterialOrder> list(String material_name, int start, int limit){
		String where = "";
		Map<String, Object> params = new HashMap<String, Object>();
		if(!"".equals(material_name)){
			where += " and material_name = :material_name";
			params.put("material_name", material_name);
		}
		
		MgrUser user = getMgrUser();
		String actortype = user.getActortype();
		logger.info("actortype:{}", actortype);
		String agent_id = "0";
		if (actortype.equals(ActorType.agent.getValue())) {
			agent_id = user.getCompanyid();
			where += " and agent_id = :agent_id";
			params.put("agent_id", agent_id);

		}
		
		return materialOrderDao.findPage(where, params, start, limit, " order by id desc");
	}
	

}
